package org.simple.web.jwt.service;

import jakarta.servlet.http.HttpServletRequest;
import org.simple.web.jwt.property.JwtAuthFilterProperty;
import org.simple.web.jwt.property.SimpleSecurityProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



/**
 * 项目名称：simple-framework
 * 类名称：RequestService
 * 类描述：RequestService
 * 创建时间：2018/11/27
 *
 * @author sisyphus   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
@Service
public class RequestService {

    @Autowired
    private SimpleSecurityProperty simpleSecurityProperty;

    public String getToken(HttpServletRequest request) {
        JwtAuthFilterProperty filterProperty = simpleSecurityProperty.getFilter();
        String authHeader = request.getHeader(filterProperty.getHeader());
        String tokenHead = filterProperty.getTokenHead();
        if (tokenHead == null) {
            tokenHead = "";
        }

        if (authHeader != null && authHeader.startsWith(tokenHead)) {
            return authHeader.substring(tokenHead.length());
        }
        return null;
    }

}
